package com.intelligencesoft.pss.controller.helper;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.intelligencesoft.pss.enums.BindingType;
import com.intelligencesoft.pss.sina.weibo.weibo4j.Oauth;
import com.intelligencesoft.pss.sina.weibo.weibo4j.model.WeiboException;
import com.intelligencesoft.pss.tencent.weibo.oauthv2.OAuthV2;
import com.intelligencesoft.pss.tencent.weibo.oauthv2.OAuthV2Client;
import com.intelligencesoft.pss.tencent.weibo.oauthv2.OAuthV2Request;

@Component
public class BindingAuthorHelper {
	
	@Autowired
	@Qualifier("configProperties")
	private Properties properties;
	
	//sina
	@Autowired
	private Oauth oauth;
	
	
	public String getAuthorUrl(BindingType bindingType) throws WeiboException{
		String oauthUrl = "";
		switch (bindingType) {
		case BINDING_SINA_WEIBO:
			oauthUrl = oauth.authorize("code");
			break;
		case BINDING_TENCENT_WEIBO:
			String clientId = properties.getProperty("tencent_app_id");
			String clientSecret = properties.getProperty("tencent_app_key");
			String redirectUri = properties.getProperty("tencent_redirect_URI");
			OAuthV2 oAuthV2 = new OAuthV2(clientId, clientSecret, redirectUri);
			
			OAuthV2Client oAuthV2Client = new OAuthV2Client();
			
			oauthUrl = oAuthV2Client.generateAuthorizationURL(oAuthV2);
			break;

		default:
			break;
		}
		return oauthUrl;
	}
	
}
